package com.dlc.yunguang.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import butterknife.BindView;
import butterknife.OnClick;
import com.dlc.commonlibrary.widget.CommonItemView;
import com.dlc.commonlibrary.widget.TitleBar;
import com.dlc.yunguang.base.BaseActivity;
import com.dlc.yunguang.net.bean.RFIDListBean;
import com.dlc.yunguang.R;

public class ProductDetailActivity extends BaseActivity {

    private static final String EXTRA_PRODUCT = "product";

    @BindView(R.id.title_bar) TitleBar mTitleBar;
    @BindView(R.id.item_rfid) CommonItemView mItemRfid;
    @BindView(R.id.item_name) CommonItemView mItemName;
    @BindView(R.id.item_spec) CommonItemView mItemSpec;
    @BindView(R.id.item_manufacturer) CommonItemView mItemManufacturer;
    @BindView(R.id.item_where) CommonItemView mItemWhere;
    @BindView(R.id.item_amount) CommonItemView mItemAmount;
    @BindView(R.id.item_wash_count) CommonItemView mItemWashCount;
    @BindView(R.id.item_wash_cost) CommonItemView mItemWashCost;

    //
    private RFIDListBean.DataBean.ListBean mProduct;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        resolveIntent();
        mTitleBar.leftExit(this);

        mItemRfid.setContent(mProduct.getRFID());
        mItemName.setContent(mProduct.getName());
        mItemSpec.setContent(mProduct.spec);
        mItemManufacturer.setContent(null); // TODO: 2017/7/25 没有 
        mItemWhere.setContent(mProduct.warehouse);
        mItemWashCount.setContent(String.valueOf(mProduct.washed));
        mItemWashCost.setContent(getString(R.string.yuan_x, mProduct.cost));
    }

    @Override
    protected int getLayoutID() {
        return R.layout.activity_product_detail;
    }

    public static Intent newIntent(Activity activity, RFIDListBean.DataBean.ListBean product) {
        Intent intent = new Intent(activity, ProductDetailActivity.class);
        intent.putExtra(EXTRA_PRODUCT, product);
        return intent;
    }

    private void resolveIntent() {

        Intent intent = getIntent();
        mProduct = intent.getParcelableExtra(EXTRA_PRODUCT);
    }

    @OnClick({ R.id.item_wash_count, R.id.item_wash_cost })
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.item_wash_count:
                startActivity(WashCountActivity.newIntent(getActivity(), mProduct.getRFID()));
                break;
            case R.id.item_wash_cost:
                startActivity(WashCostActivity.newIntent(getActivity(), mProduct.getRFID()));
                break;
        }
    }
}
